﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>入库</title>
    <script src="/Apm/js/CMSList.js"></script>
    <style>
        .list-form {
            padding: 3rem;
        }

        a {
            color: #01AAED;
        }

            a:hover {
                color: #FF5722;
            }
    </style>
</head>
<body>
    <div class="page">
        <div class="toolsbar">
            <button id="Delete" class="layui-btn layui-btn-danger">
                <i class="layui-icon">&#xe640;</i> 移除入库单
            </button>
        </div>
        <div class="content">
            <table id="tabledata" lay-filter="datalist"></table>
        </div>
    </div>
</body>

</html>
<script type="text/html" id="GuidView">
    <a id="{{d.Guid}}" onclick="ClickView(this.id)">{{d.Guid}}</a>
</script>
<script type="text/html" id="IsPrintTpl">
    <input type="checkbox" name="IsPrint" value="{{d.IsPrint}}" lay-skin="switch" disabled lay-text="是|否" {{ d.IsPrint == 1 ? 'checked' : '' }}>
</script>
<script>

    layui.use(['table', 'layer', 'element','laydate'], function () {
        var table = layui.table,
            layer = layui.layer,
            element = layui.element,
            laydate = layui.laydate;

        BindData();
        
        //删除
        $("#Delete").click(function () {
            var checkStatus = table.checkStatus('datalist');

            var rows = checkStatus.data.length;
            if (rows > 0) {
                if (rows == 1) {
                    var id = checkStatus.data[0].Guid;
                    var state = checkStatus.data[0].IsPrint;
                    if (state === 1) {
                        layer.msg("已打印的入库单不能被移除！");
                    }
                    else {
                        layer.confirm('确定移除？', { icon: 3, title: '移除' }, function (index) {

                            ajaxget({
                                url: 'api/FriendFlower/OrderStorageDelete?Token=' + MyPublic.getToken() + '&Guid=' + id,
                                success: function (data) {
                                    data = JSON.parse(data);

                                    if (data.code === "10002") {
                                        layer.close(index);
                                        BindData();
                                    }
                                    else {
                                        layer.msg(data.msg);
                                    }
                                }
                            })


                        });
                    }


                }
                else {
                    layer.msg("此模块不支持移除多条记录");
                }
            }
            else {
                layer.msg("请选择要移除的记录");
            }
        });

    });
    /**
     * 打开查看页面
     * @param id
     */
    function ClickView(id) {
        parent.AddTab('View' + id, '/FlowerManage/Storage/StorageView.html?guid=' + id, '&#xe6f3;', '入库单');
    }
    /**
     * 初始化数据
     */
    function BindData() {
        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;

            ajaxget({
                url: 'api/FriendFlower/GetOrderStorageList?Token=' + MyPublic.getToken(),
                success: function (data) {

                    table.render({
                        id: 'datalist',
                        elem: '#tabledata',
                        cols: [[//标题栏
                            { type: 'checkbox' },
                            { field: 'Guid', title: '入库单号', align: 'center', width: 180, templet: '#GuidView' },
                            { field: 'Title', title: '入库单标题', align: 'center' },
                            { field: 'SupplierName', title: '供应商', align: 'center' },
                            { field: 'WareHouseName', title: '仓库', align: 'center' },
                            { field: 'Yf', title: '应付款', align: 'right', minWidth: 100 },
                            { field: 'Sf', title: '实付款', align: 'right', minWidth: 100 },
                            { field: 'Wf', title: '未付款', align: 'right', minWidth: 100 },
                            { field: 'AddName', title: '入库人', align: 'center' },
                            { field: 'IsPrint', title: '是否打印', align: 'center', templet: '#IsPrintTpl' }
                        ]],
                        data: data,
                        height: 'full-68',
                        limit: 20,
                        limits: [20, 40, 60],
                        page: true
                    })
                }
            })

        });
    }
</script>